﻿using System.Collections.Generic;
using Cms.Data.ORM;
using Cms.Domain;
using Cms.Domain.RepositoryInterfaces;
using NHibernate;

namespace Cms.Data
{
    public class Batch
    {
        public static string GetDomain()
        {
            ISession session = NHibernateSessionFactory.OpenSession();
            ISiteRepository siteRepository = new SiteRepository(session);
            IList<Site> sites = siteRepository.GetSites();
            return sites.Count > 0 ? sites[0].Domain : null;
        }
        
        public static void ExecuteScheduledPublishings()
        {
            ISession session = NHibernateSessionFactory.OpenSession();
            IContentRepository contentRepository = new ContentRepository(session);
            contentRepository.ExecuteScheduledPublishings();
            ISiteRepository siteRepository = new SiteRepository(session);
            IList<Site> sites = siteRepository.GetSites();
            foreach (Site site in sites)
            {
                siteRepository.SaveSite(site);
            }
        }
    }
}